<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品展示页面</title>
<link rel="stylesheet" href="css/toastr.css">
</head>
<body>
	<div align="center">
		<table border="1" cellspacing="0">
			<caption>商品列表</caption>
			<tbody>
				<tr>
					<th>商品编号</th>
					<th>商品名称</th>
					<th>商品类型</th>
					<th>商品价格</th>
					<th>商品数量</th>
					<th colspan="2">操作</th>
				</tr>
				<c:forEach items="${goods_list }" var = "good">
				<tr>
					<td>${good.goodsId }</td>
					<td>${good.goodsName }</td>
					<td>${good.goodsType }</td>
					<td>${good.goodsPrice }</td>
					<td>${good.goodsCount }</td>
					<td><a href = "queryGoodsById.do?goodsId=${good.goodsId }">修改</a></td>
					<td><a href = "javascript:void(0)" onclick="deleteGoods(${good.goodsId })">删除</a></td>
				</tr>
				</c:forEach>
			</tbody>
		</table>
		<p>一共${page.pages }页</p>
		<a href = "queryAll.do?page=${page.firstPage }">首页</a>
		<a href = "queryAll.do?page=${page.prePage }">上一页</a>
		<a href = "queryAll.do?page=${page.nextPage }">下一页</a>
		<a href = "queryAll.do?page=${page.lastPage }">尾页</a>
	</div>

</body>

<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/toastr.js"></script>
<script type="text/javascript">
	function deleteGoods(goodsId) {
		$.ajax({
			url:"delete.do",
			type:"POST",
			data:{"goodsId":goodsId},
			success:function(data){
				toastr.info(data);
				window.location.href="queryAll.do"
			},
			error:function(){
				toastr.error("出错，异常");
			}
		})
	}

</script>
</html>